package org.dromara.dashboard.controller;

import org.dromara.common.core.domain.R;
import org.dromara.dashboard.domain.vo.IndexChartsVo;
import org.dromara.dashboard.domain.vo.LineBarChartData;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
首页Echarts数据
 */
@RestController
@RequestMapping("/index/middle")
public class IndexMiddleController {


    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    //首页用户占比数据
    @GetMapping("/pie")
    public R<IndexChartsVo> pieChart(){

        IndexChartsVo indexChartsVo = new IndexChartsVo();
        indexChartsVo.setLeft(78);
        indexChartsVo.setRight(48);
        return R.ok(indexChartsVo);
    }

     // 折线图
    @GetMapping("/lineChartData/{timeArray}")
    public R<LineBarChartData> lineChartData(@PathVariable String[] timeArray){
        List<Integer> inArray = new ArrayList<>();
        List<Integer> outArray = new ArrayList<>();

        for (int i = 0; i < timeArray.length; i++) {
            Random random = new Random();
            Integer resultNum = random.nextInt(50) + 1; // nextInt(n) 生成 0 到 n-1 的随机数
            inArray.add(resultNum);
        }

        for (int i = 0; i < timeArray.length; i++) {
            Random random = new Random();
            int resultNum = random.nextInt(50) + 1; // nextInt(n) 生成 0 到 n-1 的随机数
            outArray.add(resultNum);
        }

        LineBarChartData entity = new LineBarChartData(timeArray, inArray,outArray);

        return R.ok(entity);
    }

}
